﻿Public Class SearchRolesForm
    Public idSelect As Integer

    Public codigoSelected As Integer

    Private Sub SearchRolesForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GenericAdministrator.loadGrid(Me.dgvRole, Me.bdnSearchRole, GenericAdministrator.searchDataByFilter(New Role()))

        'GenericAdministrator.loadGrid(Me.dgvRole, Me.bndSearchRole, ResourceAdministrator.search)
        Me.setDataGridViewHeaders()
    End Sub

    Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Dim id As Integer = Nothing
        If Me.txtid.Text <> "0" Then
            If Me.txtid.Text <> "" Then
                id = CType(Me.txtid.Text, Integer)
            End If
            Dim role As New Role(id, Me.txtName.Text, Nothing)
            GenericAdministrator.loadGrid(Me.dgvRole, Me.bdnSearchRole, GenericAdministrator.searchDataByFilter(role))
        Else
            MsgBox("Ha ingresado un codigo invalido.", vbCritical, "Importante")
        End If

    End Sub



    Private Sub setDataGridViewHeaders()
        Me.dgvRole.Columns(0).HeaderText = "Codigo"
        Me.dgvRole.Columns(1).HeaderText = "Nombre"
        Me.dgvRole.Columns(2).HeaderText = "Descripcion"
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Dim id As Integer = Me.dgvRole.CurrentRow.Cells(0).Value
        Dim rol As New Role(id, Name, Nothing)
        Dim confirmacion As Integer
        confirmacion = MsgBox("Esta seguro que desea eliminar el Rol seleccionad?", vbYesNo + vbQuestion + vbDefaultButton2, "Salir")

        If confirmacion = vbYes Then
            GenericAdministrator.deletedById(rol)
            GenericAdministrator.loadGrid(Me.dgvRole, Me.bdnSearchRole, GenericAdministrator.searchDataByFilter(rol))
        End If
    End Sub



    Private Sub bdnEditButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bdnEditButton.Click
        idSelect = dgvRole.CurrentRow.Cells(0).Value
        Me.Close()
        Dim roleForm As New RoleForm(Me)
        RoleForm.Show()

    End Sub

    Private Sub txtid_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtid.KeyPress
        ViewValidators.isInteger(e)
    End Sub

End Class